import time
from util.singelMode import  singleton
@singleton
class Ctime:
    def __init__(self):
        pass
    def __call__(self):
        return self
    @staticmethod
    def beginEpochTimestamp():
        #转换成时间数组
        timeArray = time.strptime("2018-04-30 00:00:00", "%Y-%m-%d %H:%M:%S")
        #转换成时间戳
        timestamp = time.mktime(timeArray)
        return timestamp

    @staticmethod
    def getTimestoEpochTime(tm=-1):
        if(tm == -1):
            tm= time.time()
        d = Ctime.beginEpochTimestamp()
        return tm - d

    @staticmethod
    def getNowTimestamp():
        return  time.time()
    
    @staticmethod
    def getSlotNumber(epochTime=-1):
        if(epochTime == -1):
            epochTime =Ctime.getTimestoEpochTime()
        
        return (epochTime/10)
    
    @staticmethod
    def getSlotTime(slotNumber):
        return slotNumber*10

    @staticmethod
    def getNextSlot():
        slot =  Ctime.getSlotNumber()
        return slot + 1
    
    @staticmethod
    def getLastSlot(currentSlot):
        return currentSlot + 101

